package com.wing.bill.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.bill.service.RepairAndScarpInReportService;
import com.wing.cabinet.model.response.StorageInventoryInoutVO;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.web.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Validated
@Api(value = "Admin-刀具柜报废存入记录报表", tags = "#/bill/scarpInReport")
@RestController("scarpInReportController")
@RequestMapping("bill/admin/scarpInReport")
@RequiredArgsConstructor
public class ScarpInReportController {

    private final RepairAndScarpInReportService repairAndScarpInReportService;

    private final Integer businessType = 3;
    @ApiOperation(value = "顶部趋势图", notes = "报废统计(按天)")
    @GetMapping("/list")
    public JsonResult list(
            @RequestParam("param") String param //柱状图饼状图的下拉选 不同的选项 qua 数量 money 金额
    ){

        return repairAndScarpInReportService.list(businessType,param,JwtUtils.getEnterpriseCode());
    }

    @ApiOperation(value = "顶部格子", notes = "搜索")
    @GetMapping("/topCell")
    public JsonResult topCell(
            @RequestParam("click")Integer click,
            @RequestParam("startTime")String startTime,
            @RequestParam("endTime")String endTime,
            @RequestParam("mainCabCode")String mainCabCode
    ){
        return repairAndScarpInReportService.topCell(businessType,startTime,endTime,click,mainCabCode,JwtUtils.getEnterpriseCode());
    }

    @ApiOperation(value = "物料排名(按物料)", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectParam", value="下拉选项参数(系列-spu 编号-sku 品牌-brand 类型-type 分类-category)", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "param", value = "开关参数(数量-qua 金额-money)",  dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "tab", value = "tab参数(总览tab-tab0 物料tab-tab1)",  dataType = "String", paramType = "query")
    })
    @GetMapping("/midFirstChartNew")
    public JsonResult midFirstChartNew(
            @RequestParam("selectParam")String selectParam
            ,@RequestParam("param")String param
            ,@RequestParam("tab")String tab
            ,@RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
    ){
        return repairAndScarpInReportService.queryStatisticsByParam(businessType,selectParam,param,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),"sku",tab,null);
    }

    @ApiOperation(value = "物料排名(按柜子)", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectParam", value="下拉选项参数(主柜-main 副柜-desk)", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "param", value = "开关参数(数量-qua 金额-money)",  dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "tab", value = "tab参数(总览tab-tab0 柜子tab-tab1)",  dataType = "String", paramType = "query")
    })
    @GetMapping("/midSecondChartNew")
    public JsonResult midSecondChartNew(
            @RequestParam("selectParam")String selectParam
            ,@RequestParam("param")String param
            ,@RequestParam("tab")String tab
            ,@RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
    ){
        return repairAndScarpInReportService.queryStatisticsByParam(businessType,selectParam,param,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),"cab",tab,null);
    }

    @ApiOperation(value = "物料排名(按组织)", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectParam", value="下拉选项参数(责任人-person 部门-department 成本中心-costCenter)", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "param", value = "开关参数(数量-qua 金额-money)",  dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "tab", value = "tab参数(总览tab-tab0 组织tab-tab1)",  dataType = "String", paramType = "query")
    })
    @GetMapping("/midThirdChartNew")
    public JsonResult midThirdChartNew(
            @RequestParam("selectParam")String selectParam
            ,@RequestParam("param")String param
            ,@RequestParam("tab")String tab
            ,@RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
    ){
        return repairAndScarpInReportService.queryStatisticsByParam(businessType,selectParam,param,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),"org",tab,null);
    }

    @ApiOperation(value = "物料排名(按使用情况)", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectParam", value="下拉选项参数(工单-workOrder 车间-workShop 设备-device)", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "param", value = "开关参数(数量-qua 金额-money)",  dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "tab", value = "tab参数(总览tab-tab0 使用情况tab-tab1)",  dataType = "String", paramType = "query")
    })
    @GetMapping("/midFourChartNew")
    public JsonResult midFourChartNew(
            @RequestParam("selectParam")String selectParam
            ,@RequestParam("param")String param
            ,@RequestParam("tab")String tab
            ,@RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
    ){
        return repairAndScarpInReportService.queryStatisticsByParam(businessType,selectParam,param,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),"use",tab,null);
    }

    @ApiOperation(value = "原因统计", notes = "搜索")
    @GetMapping("/midFiveChartNew")
    public JsonResult midFiveChartNew(
            @RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
            ,String skuCode
            ,String deviceCode
            ,Long creator
            ,Long workOrderId
    ){
        Map<String,Object> screenParam = new HashMap<>();
        screenParam.put("skuCode",skuCode);
        screenParam.put("deviceCode",deviceCode);
        screenParam.put("creator",creator);
        screenParam.put("workOrderId",workOrderId);

        return repairAndScarpInReportService.queryStatisticsByParam(businessType,null,null,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),"reason",null,screenParam);
    }

    @ApiOperation(value = "报废记录列表", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/dataList")
    public PageResult<StorageInventoryInoutVO> dataList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam("startTime")String startTime
            ,@RequestParam("endTime")String endTime
            ,@RequestParam("mainCabCode") String mainCabCode
    ) {
        Page<StorageInventoryInoutVO> pg = new Page<>(page, limit);

        IPage<StorageInventoryInoutVO> list = repairAndScarpInReportService.data(businessType,startTime,endTime,mainCabCode,JwtUtils.getEnterpriseCode(),pg);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }
}
